﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TeamBuy.AccessWebUI.Components
{
    public partial class Head : System.Web.UI.UserControl
    {
        TeamBuy.AccessService.TeamBuyCityService getCity = new AccessService.TeamBuyCityService();

        private int currentCityID;
        public int CurrentCityID
        {
            get
            {
                return currentCityID;
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {

            if (TeamBuySession.IsUserLoggedIn == true)
            {
                ltlUserName.Text = Session["UserName"].ToString();
                pnlLogin.Visible = false;
                pnlAdmin.Visible = false;
                pnlUser.Visible = true;
            }
            if (TeamBuySession.IsAdminLoggedIn == true)
            {
                ltlAdminName.Text = Session["AdminName"].ToString();
                pnlUser.Visible = false;
                pnlLogin.Visible = false;
                pnlAdmin.Visible = true;
            }

            if (Convert.ToString(Request.QueryString["City"]) != "" && Convert.ToString(Request.QueryString["City"]) != null)
            {
                ltlCurrentCity.Text = getCity.GetCityByID(Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"])));
                TeamBuySession.SaveDefaultCityCookie(Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"])));
                currentCityID = Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"]));
            }
            else
            {
                if (TeamBuySession.GetDefaultCityCookie() > 0)
                {
                    ltlCurrentCity.Text = getCity.GetCityByID(TeamBuySession.GetDefaultCityCookie());
                    TeamBuySession.SaveDefaultCityCookie(TeamBuySession.GetDefaultCityCookie());
                    currentCityID = TeamBuySession.GetDefaultCityCookie();
                }
                else
                {
                    ltlCurrentCity.Text = getCity.GetCityByID(TeamBuy.AccessService.TeamBuySystemInfo.DefaultCityID);
                    TeamBuySession.SaveDefaultCityCookie(TeamBuy.AccessService.TeamBuySystemInfo.DefaultCityID);
                    currentCityID = TeamBuy.AccessService.TeamBuySystemInfo.DefaultCityID;
                }
            }
        }

        protected void lbtnLogoff_Click(object sender, EventArgs e)
        {
            TeamBuySession.DeleteUserSession();
            TeamBuySession.DeleteAdminSession();
            if (TeamBuySession.IsUserLoggedIn != true && TeamBuySession.IsAdminLoggedIn != true)
            {
                pnlLogin.Visible = true;
                pnlUser.Visible = false;
                pnlAdmin.Visible = false;
                Response.Redirect(Request.Url.ToString());
                //Response.Redirect("/Default.aspx");
            }

            //string a = (Convert.ToInt32(Eval("CityID")) == Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"])) ? "current" : "") == "current" ? "current" : (Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"])) == 0 ? "4" : "");
            //string c = (Convert.ToInt32(Eval("CityID")) == Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"])) ? "current" : "") == "current" ? "current" : (Convert.ToInt32(TeamBuy.Common.PublicFunction.DESDecrypt(Request.QueryString["City"])) == 0 ? (TeamBuy.AccessWebUI.TeamBuySession.GetDefaultCityCookie() > 0 ? (TeamBuy.AccessWebUI.TeamBuySession.GetDefaultCityCookie() == Convert.ToInt32(Eval("CityID")) ? "current" : "") : (Convert.ToInt32(Eval("CityID")) == TeamBuy.AccessService.TeamBuySystemInfo.DefaultCityID ? "current" : "")) : "");
            //string b = (TeamBuy.AccessWebUI.TeamBuySession.GetDefaultCityCookie() > 0 ? (TeamBuy.AccessWebUI.TeamBuySession.GetDefaultCityCookie() == Convert.ToInt32(Eval("CityID")) ? "current" : "") : (Convert.ToInt32(Eval("CityID")) == TeamBuy.AccessService.TeamBuySystemInfo.DefaultCityID ? "current" : ""));
        }

    }
}